<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('体检病人列表')"/>
    <th:block th:include="include :: bootstrap-editable-css" />
</head>
<body class="gray-bg">
<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="user-form">
                    <div class="select-list">
                        <ul>
                            <li>
                                条形码：<input type="text" name="patientCode" id="patientCode"/>
                            </li>
                            <li class="select-time">
                                <label>登记时间： </label>
                                <input type="text" class="time-input" id="dateRegisterStart" placeholder="开始时间"
                                       name="dateRegisterStart"  required/>
                                <span>-</span>
                                <input type="text" class="time-input" id="dateRegisterEnd" placeholder="结束时间" name="dateRegisterEnd"
                                       required/>
                            </li>
                            <li class="select-time">
                                <label>扫码时间： </label>
                                <input type="text" class="time-input" id="scanTimeStart" placeholder="开始时间"
                                       name="scanTimeStart"  required/>
                                <span>-</span>
                                <input type="text" class="time-input" id="scanTimeEnd" placeholder="结束时间" name="scanTimeEnd"
                                       required/>
                            </li>
                            <li>
                                处理状态：<select name="id_cis">
                                <option value="">全部</option>
                                <option value="1">已回收</option>
                            </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                        class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
<!--                <a class="btn btn-primary single disabled" onclick="$.operate.editTab()">-->
<!--                    <i class="fa fa-edit"></i> 修改-->
<!--                </a>-->
                <a class="btn btn-warning" onclick="$.table.exportExcel()">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
</div>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: bootstrap-table-editable-js" />
<script th:inline="javascript">
    var prefix = ctx + "pub/physcialExam";

    // var curDate = new Date();
    // var nextDate = new Date(curDate.getTime() + 24*60*60*1000); //后一天
    // var start = curDate.getFullYear() + '-' + (curDate.getMonth()+1) + '-' + curDate.getDate();
    // var end = nextDate.getFullYear() + '-' + (nextDate.getMonth()+1) + '-' + nextDate.getDate();
    // $('#dateRegisterStart').attr('value',start);
    // $('#dateRegisterEnd').attr('value',end);

    $(function () {
        queryPatientList();
        $('#patientCode').bind('keypress', function (event) {
            if (event.keyCode == "13"){
                $.table.search(null,null,{
                    id_cis : ''
                });
                $("#patientCode").val("");
            }
        });

        // $("#dateRegisterStart").datetimepicker({
        //     format: 'yyyy-mm-dd',
        //     minView: "month",
        //     todayBtn:  true,
        //     autoclose: true,
        //     endDate : new Date(),
        // }).on('changeDate', function(event) {
        //     event.preventDefault();
        //     event.stopPropagation();
        //     var startTime = event.date;
        //     $('#dateRegisterEnd').datetimepicker('setStartDate', startTime);
        // });
        //
        // $("#dateRegisterEnd").datetimepicker({
        //     format: 'yyyy-mm-dd',
        //     minView: "month",
        //     todayBtn:  true,
        //     autoclose: true,
        //     endDate : new Date(),
        // }).on('changeDate', function(event) {
        //     event.preventDefault();
        //     event.stopPropagation();
        //     var endTime = event.date;
        //     $("#dateRegisterStart").datetimepicker('setEndDate', endTime);
        // });
    });

    function queryPatientList() {
        var options = {
            url: prefix + "/list",
            // createUrl: prefix + "/add",
            // updateUrl: prefix + "/edit/{id}",
            // removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            // importUrl: prefix + "/importData",
            // importTemplateUrl: prefix + "/importTemplate",
            // sortName: "createTime",
            // sortOrder: "desc",
            // modalName: "病人建档信息",
            firstLoad: false,
            onEditableSave: onEditableSave,
            clickToSelect: true,
            modalName: "核酸检测列表",
            singleSelect: true,
            columns: [{
                checkbox: true
            },
                {
                    field: 'patientCode',
                    title: '条形码'
                },
                {
                    field: 'patientName',
                    title: '姓名'
                },
                {
                    field: 'sex',
                    title: '性别'
                },
                {
                    field: 'age',
                    title: '年龄',
                },
                {
                    field: 'patientCardNo',
                    title: '住院号'
                },
                {
                    field: 'idCardNo',
                    title: '身份证号'
                },
                {
                    field: 'phone',
                    title: '手机'
                },
				{
					field: 'id_cis',
					title: '是否回收',
                    align: 'center',
                    editable : {
                        type : 'select',
                        title : '状态',
                        source : [{
                            value : 1,
                            text : "已回收"
                        }, {
                            value : '',
                            text : "未回收"
                        }]
                    }
				},
                {
                    field: 'address',
                    title: '地址'
                },
				{
					field: 'org_name',
					title: '单位'
				},
				{
					field: 'dateRegister',
					title: '登记时间'
				},
                {
                    field: 'scanTime',
                    title: '扫码时间'
                }
            ]
        };
        $.table.init(options);
    }

    function onEditableSave (field, row, oldValue, $el) {
        // alert("字段名：" + field + "，当前值：" + row[field]  + "，旧值：" + oldValue + '---' + row['patientCode']);
        $.operate.post(
            prefix + "/update",
            {
                'patientCode' : row['patientCode'],
                'status' : row[field]
            },
            function (data) {
                $.modal.msgSuccess(data.msg);
            }
        );
    }

</script>
</body>
</html>